/**
 * @param {string} s
 * @return {string}
 */
 var reverseWords = function(s) {
  let i = s.length - 1
  let j = 0
  let res = []
  while(i >= 0){
    if(s[i] !== ' '){
      j = i
      while(i >= 0 && s[i] !== ' '){
        i--
      }
      res.push(s.slice(i+1,j+1))
    }
    i--
  }
  return res.join(' ')
};